package com.amigo.online.provider.manager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.provider.manager.model.entity.MerchantAdvTbl;
import com.amigo.online.provider.manager.service.MerchantAdvTblService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@RestController
@RequestMapping(value = "/merchantAdvTbl", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class MerchantAdvTblController extends BaseController {

    @Resource
    private MerchantAdvTblService merchantAdvTblService;

    @PostMapping(value = "/getMerchantAdvTblList")
    public ResponseEntity<Response> getMerchantAdvTblList(@RequestBody MerchantAdvTbl merchantAdvTbl) {
        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(merchantAdvTbl.getPageNo(), 10);
        List<MerchantAdvTbl> merchantAdvTblList = merchantAdvTblService.selectMerchantAdvTblList(merchantAdvTbl);
        result.put("merchantAdvTblList", merchantAdvTblList);
        result.put("pagetotal", page.getTotal());

        return success(result);
    }

    @PostMapping(value = "/saveMerchantAdvTbl")
    public ResponseEntity<Response> saveMerchantAdvTbl(@RequestBody MerchantAdvTbl merchantAdvTbl) {
        return success(merchantAdvTblService.insertMerchantAdvTbl(merchantAdvTbl));
    }

    @PutMapping(value = "/updateMerchantAdvTbl")
    public ResponseEntity<Response> updateMerchantAdvTbl(@RequestBody MerchantAdvTbl merchantAdvTbl) {
        return success(merchantAdvTblService.updateMerchantAdvTbl(merchantAdvTbl));
    }

    @PutMapping(value = "/deleteMerchantAdvTbl")
    public ResponseEntity<Response> deleteMerchantAdvTbl(@RequestBody MerchantAdvTbl merchantAdvTbl) {
        return success(merchantAdvTblService.deleteMerchantAdvTbl(merchantAdvTbl));
    }

}
